package roborally.program.command;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import roborally.itemsonboard.Robot;

/**
 * A class representing a flow commands. These commands consists of several other commands.
 * Examples are the while-statement, the sequence-statement and the if-then-else-then-statement.
 * 
 * @author Molderez Tom, 2de bach Ingenieurswetenschappen Computerwetenschappen-Elektrotechniek and Reniers Jorn, 2de bach Ingenieurswetenschappen Werktuigkunde-Computerwetenschappen
 * @version 1.0
 *
 */
public abstract class FlowCommand extends Command {
	
	protected FlowCommand() {
		super();
	}
	
	public List<Command> getInternalCommands() {
		return Collections.unmodifiableList(internalCommands);
	}
	
	public void addAsCommands(Collection<? extends Command> commands) {
		internalCommands.addAll(commands);
		//lege lijst moet mogelijk zijn.
	}

	private final List<Command> internalCommands = new ArrayList<Command>();
	
	@Override
	public void execute(Robot robot) throws IllegalArgumentException {
		for(Command lusCommand : internalCommands)
			lusCommand.execute(robot);
	}
	
	@Override
	public String write() {
		String write = new String();
		for(Command lusCommand : internalCommands)
			write = write + " " + lusCommand.write();
		return write;
	}
}
